package ru.dadle8.service.impl;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import ru.dadle8.service.api.ExecutorFactory;
import ru.dadle8.service.api.MessageExecutor;
import ru.dadle8.service.api.action.ActionExecutor;
import ru.dadle8.service.api.callback.CallbackExecutor;
import ru.dadle8.service.api.command.CommandExecutor;

@Service
@RequiredArgsConstructor
public class ExecutorFactoryImpl implements ExecutorFactory {
    private final ActionExecutor actionExecutor;
    private final CommandExecutor commandExecutor;
    private final CallbackExecutor callbackExecutor;

    @Override
    public MessageExecutor getMessageExecutor(Update update) {
        if (update.hasMessage()) {
            if (update.getMessage().hasText()) {
                // parse action message
                Message inMess = update.getMessage();
                if (inMess.getText().startsWith("/")) {
                    return actionExecutor;
                }
            }

            // parse other messages by command state
            return commandExecutor;
        } else if (update.hasCallbackQuery()) {
            return callbackExecutor;
        }
        // check delete and block
        return null;
    }
}
